package cjq.demo.thread.ch6_4;

import java.util.concurrent.PriorityBlockingQueue;

/**
 * Created by Administrator on 2016/5/4.
 */
public class Main {
    public static void main(String[] args) {
        PriorityBlockingQueue<Event> queue = new PriorityBlockingQueue<>();

        Thread taskThreads[] = new Thread[5];

        for (int i = 0; i < taskThreads.length; i++) {
            Task task = new Task(i,queue);
            taskThreads[i] = new Thread(task);

        }

        for (int i = 0; i < taskThreads.length; i++) {
            taskThreads[i].start();
        }

        for (int i = 0; i < taskThreads.length; i++) {
            try{
                taskThreads[i].join();
            }catch(InterruptedException e){
                e.printStackTrace();
            }
        }

        System.out.println("Main : Queue Size: "+queue.size());
        for (int i = 0; i < taskThreads.length; i++) {
            Event event = queue.poll();
            System.out.println("Thread : "+event.getThread()+" Priority "+event.getPriority());
        }

        System.out.println("Main: Queue Size : "+queue.size());
        System.out.println("Main : End of the program. ");
    }
}
